package org.aspire.math.geom.event;

/******************************************************************************
 * An event triggered by the change in the x and/or y of the location data.
 * This event contains the source of change in data and the amount of change in
 * one or both stored in floating point precision. The change can also be
 * retrieved in integer precision.
 * 
 * @author JPACarabuena
 *****************************************************************************/
public class PointEvent {

	// ========================================================================
	// Constants
	// ========================================================================
	
	/**
	 * The source of change is the x data.
	 */
	public static int SRC_X 	= 1;
	
	/**
	 * The source of change is the y data.
	 */
	public static int SRC_Y 	= 2;
	
	/**
	 * The source of change is both the x and y data.
	 */
	public static int SRC_BOTH		= 3;

	// ========================================================================
	// Static Methods
	// ========================================================================
	
	// ========================================================================
	// Fields
	// ========================================================================
	
	/**
	 * Holds the value for the source of data change. There are three different
	 * source of change in location: X, Y, and Both.
	 */
	protected int source;
	
	/**
	 * The change in value of the x in floating point precision. A positive
	 * value denotes an increase in the x while a negative value represents a
	 * decrease.
	 */
	protected float deltaX;
	
	/**
	 * The change in value of the y in floating point precision. A positive 
	 * value denotes an increase in the y while a negative value represents a
	 * decrease.
	 */
	protected float deltaY;
	
	// ========================================================================
	// Constructors
	// ========================================================================
	
	/**
	 * Creates a new location change event with the specified source of change
	 * and the floating point value of the changes in x and/or y.
	 * 
	 * @param source	the source of change.
	 * @param deltaX	the change in x.
	 * @param deltaY	the change in y.
	 */
	public PointEvent(int source, float deltaX,
			float deltaY) {
		this.source = source;
		this.deltaX = deltaX;
		this.deltaY = deltaY;
	}
	
	// ========================================================================
	// Getters & Setters
	// ========================================================================
	
	/**************************************************************************
	 * Checks the source of change in the location data.
	 * 
	 * @return	The integer flag for the source. 
	 *************************************************************************/
	public int getSource() {
		return this.source;
	}
	
	/**************************************************************************
	 * Checks the change in x that triggered the event in floating point
	 * precision.
	 * 
	 * @return	The change in x.
	 *************************************************************************/
	public float getXChange() {
		return this.deltaX;
	}
	
	/**************************************************************************
	 * Checks the change in x that triggered the event in integer precision.
	 * 
	 * @return	The change in x.
	 *************************************************************************/
	public int getXChangeInt() {
		return Math.round(this.deltaX);
	}
	
	/**************************************************************************
	 * Checks the change in y that triggered the event in floating point
	 * precision.
	 * 
	 * @return	The change in y.
	 *************************************************************************/
	public float getYChange() {
		return this.deltaY;
	}
	
	/**************************************************************************
	 * Checks the change in y that triggered the event in integer precision.
	 * 
	 * @return	The change in y.
	 *************************************************************************/
	public int getYChangeInt() {
		return Math.round(this.deltaY);
	}
	
	// ========================================================================
	// Override Methods
	// ========================================================================
	
	// ========================================================================
	// Methods
	// ========================================================================
	
	/**************************************************************************
	 * Checks if the change happened in the x data only.
	 * 
	 * @return Whether or not the change is triggered by the x data only.
	 *************************************************************************/
	public boolean isChangeInXOnly() {
		return (this.source == PointEvent.SRC_X);
	}
	
	/**************************************************************************
	 * Checks if the change happened in the y data only.
	 * 
	 * @return Whether or not the change is triggered by the y data only.
	 *************************************************************************/
	public boolean isChangeInYOnly() {
		return (this.source == PointEvent.SRC_Y);
	}
	
	/**************************************************************************
	 * Checks if the change happened in both the x and y data.
	 * 
	 * @return Whether or not the change is triggered by both the x and y data.
	 *************************************************************************/
	public boolean isChangeBoth() {
		return (this.source == PointEvent.SRC_BOTH);
	}
	
	// ========================================================================
	// Inner & Anonymous Classes
	// ========================================================================
}